package com.twu.biblioteca.session.actions;

import com.twu.biblioteca.Movie;
import com.twu.biblioteca.session.Session;
import com.twu.biblioteca.session.SessionAction;
import com.twu.biblioteca.session.SessionOption;

public class ReturnMovieAction extends SessionAction{


    public ReturnMovieAction(SessionOption option, Session session) {
        super(option, session);
    }

    @Override
    public String[] getActionInput() {
        return this.getSession().getUi().readMovieDetails();
    }

    @Override
    public void performAction(String[] args) {

        for (Movie movie : this.getSession().getLibrary().getMovies()) {
            if (movie.compareWithDetails(args[0], args[1], args[2])) {
                movie.setCheckedOut(false);
                this.getSession().getCurrentlyLoggedIn().getCheckedOutItems().remove(movie);
                this.getSession().getUi().successMovieReturn();
                return;
            }
        }
        this.getSession().getUi().invalidMovieReturn();
    }
}
